package action;

import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Disciplina;
import padraoMemento.MementoDisciplina;

public class ExcluirDisciplinaAlteradaAction extends ManterDisciplinaAction {

    @Override
    public void setParametros(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    
            
            request.setAttribute("editar", "readonly");
            request.setAttribute("excluir", "readonly");
            
            int codDisciplina = Integer.parseInt(request.getParameter("codDisciplina"));
            Disciplina disciplina =  MementoDisciplina.obterDisciplina(codDisciplina);
            request.setAttribute("disciplina", disciplina);
            String preRequisitosSerialized = "";
            for (Disciplina preRequisito : disciplina.getDisciplinasForCodDisciplinaPreRequisito()) {
                preRequisitosSerialized = preRequisitosSerialized + preRequisito.getCodDisciplina() + ",";
            }
            request.setAttribute("preRequisitosSerialized", preRequisitosSerialized);
            
     
    }

    @Override
    public void efetuaPersistencia(Disciplina disciplina) throws ServletException {
        MementoDisciplina.excluirDisciplina(disciplina);
       
    }

}
